home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_055 / csh / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  127 lines

  1.  
  2. /*
  3.  * MAIN.C
  4.  *
  5.  * Matthew Dillon, 24 Feb 1986
  6.  * (c)1986 Matthew Dillon     9 October 1986
  7.  *
  8.  * version 2.05M (Manx Version and Additions) by Steve Drew 20-Jan-87
  9.  *
  10.  */
  11.  
  12. #include "shell.h"
  13.  
  14. void cleanupconsole(), initconsole();
  15. extern char *btocstr();
  16. extern struct FileLock *Clock; 
  17.  
  18. char Inline[256];
  19. char stdout_buff[STDBUF]; 
  20. main(argc, argv)
  21. register char *argv[];
  22. {
  23.    char *rawgets();
  24.    char *prompt;
  25.    register int i;
  26.    extern int Enable_Abort;
  27.    init_vars();
  28.    init();
  29.    seterr();
  30.    do_cd(NULL, -1);
  31.    
  32.    Enable_Abort = 0;
  33.      
  34.    for (i = 1; i < argc; ++i) {
  35.       if (argv[i][0] == '-' && argv[i][1] == 'c') {
  36.         Inline[0] = ' ';
  37.         Inline[1] = '\000';
  38.         while (++i < argc) {
  39.         strcat(Inline,argv[i]);
  40.         strcat(Inline," ");
  41.         }
  42.         exec_command(Inline);
  43.         main_exit(0);
  44.         }
  45.       strcpy (Inline, "source ");
  46.       strcat (Inline, argv[i]);
  47.       av[1] = argv[i];
  48.       do_source (Inline);
  49.    }
  50.    
  51.    for (;;) {
  52.       if ((prompt = get_var (LEVEL_SET, V_PROMPT)) == NULL)
  53.          prompt = "$ ";
  54.       if (breakcheck()) {
  55.          while (WaitForChar(Input(), 1L))
  56.             gets(Inline);
  57.       }
  58.       if (Quit || !rawgets(Inline, prompt))
  59.          main_exit(0);
  60.       breakreset();
  61.       if (*Inline)
  62.          exec_command(Inline);
  63.    }
  64. }
  65.  
  66. init_vars()
  67. {
  68.    if (IsInteractive(Input()))
  69.       set_var (LEVEL_SET, V_PROMPT, "$ ");
  70.    else
  71.       set_var (LEVEL_SET, V_PROMPT, "");
  72.    set_var (LEVEL_SET, V_HIST,   "20");
  73.    set_var (LEVEL_SET, V_LASTERR, "0");
  74.    set_var (LEVEL_SET, V_PATH, "ram:,ram:c/,c:,df1:c/,df0:c/");
  75. }
  76.  
  77. init()
  78. {
  79.  
  80.  
  81.    static char pipe1[32], pipe2[32];
  82.  
  83.    initconsole();
  84.  
  85.    stdout->_buff = stdout_buff;
  86.    stdout->_buflen = STDBUF;  
  87.  
  88.    Myprocess = (struct Process *)FindTask(0L);
  89.    Uniq  = (long)Myprocess;
  90.    Pipe1 = pipe1;
  91.    Pipe2 = pipe2;
  92.    sprintf (pipe1, "ram:pipe1_%ld", Uniq);
  93.    sprintf (pipe2, "ram:pipe2_%ld", Uniq);
  94. }
  95.  
  96.  
  97. main_exit(n)
  98. {
  99.    cleanupconsole(0);
  100.    exit (n);
  101. }
  102.  
  103. breakcheck()
  104. {
  105.    if (SetSignal(0L,0L) & SIGBREAKF_CTRL_C)
  106.       return (1);
  107.    else
  108.       return (0);
  109. }
  110.  
  111. breakreset()
  112. {
  113.    SetSignal(0L, SIGBREAKF_CTRL_C);
  114. }
  115.  
  116.  
  117. /* this routine causes manx to use this Chk_Abort() rather than it's own */
  118. /* otherwise it resets our ^C when doing any I/O (even when Enable_Abort */
  119. /* is zero).  Since we want to check for our own ^C's              */
  120.  
  121. Chk_Abort()
  122. {
  123. return(0);
  124. }
  125.  
  126.  
  127.